<? 
session_start();
if(!session_is_registered(uid)){
    echo "You have to login to view this page!</br></br>";
    echo "Click here to return to the "; 
    echo '<a href="./../index.php" title="Login">Login Page</a></br></br>';
    echo "Or sign up using this link ";
    echo '<a href="./../Registration/registration.html" title="Registration">Registration Page</a>';
exit();
}
else

    //Manual SQL Connection
    $con = mysql_connect("localhost", "root", "root") or die ( "Error connectiong to DB: ".mysql_error());
       
    mysql_select_db("reeferslog", $con) or die ( "Error selecting specific DB, reefeerslog: ".mysql_error());

if ($_GET['action'] == 'edit') {
    
    $qry = "select  * from water_tests where user_id='". $_SESSION['uid'] ."' and test_date='".$_GET['test_date']."'";
    
    $results = mysql_query($qry)or die(mysql_error($con));

    extract(mysql_fetch_assoc($results));
    
}else {
    //set values blanks
    $test_date = ''; 
    $temp = 0;
    $dkh = 0; 
    $amon = 0;
    $nitrate = 0;
    $po4 = 0;
    $orp = 0;
    $cal = 0;
    $mag = 0;
    $salinity = 0;
    
    //Date variables
    $day = 0;
    $month = 0;
    $year = 0;   
    
    //Function to make a valid date input
    $test_date = $year."-".$month."-".$day;
    
    list($year, $month, $day) = explode("-", $test_date);
}

?>

<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><?php echo ucfirst($_GET['action']); ?>Test Log</title>
        <link rel="stylesheet" type="text/css" href="http://localhost/ReefersLogApp/CSS/Generalpagelayout.css" />
    
        <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>
        <script type='text/javascript' src='./../scripts/js/jquery.ba-hashchange.min.js'></script>
        <script type='text/javascript' src='./../scripts/js/dynamicpage.js'></script>  
</head>

<div id="container">
	<div id="header">
            <h1>
		Reefers Log
            </h1>
	</div>
	<div id="navigation">
		<ul>
			<li><a href="./../WelcomePage/WelcomePage.php">Home</a></li>
			<li><a href="./../Profile/userprofile.php">Profile</a></li>
			<li><a href="./../Tools/tools.php">Tools</a></li>
			<li><a href="./../Logout/logout.php">Logout</a></li>
		</ul>
	</div>
	<div id="content-container">
		<div id="section-navigation">
                    <object id="loader" name="frameloader" type="text/html" data="http://localhost/ReefersLogApp/Welcome/WelcomePage.php/"></object>
			<ul>
                        
				<li><a href="viewtests.php">Water Test History</a></li>				
                                <li><a href="./../Maintenance/maintenancelog.php">Veiw Maintenance Log</a></li>
                                <li><a href="./../Maintenance/waterchangelog.php">View Water Changes</a></li>
				
			</ul>
		</div>
		<div id="content">
                    <h2>
                        Your Aquarium Statistics:
                    </h2>
                    <p>
                        Complete the form below to record your water chemistry values..
                    </p>		
                    <h2>
                        Water Test Log:
                    </h2>

    <form action="commitedit.php?action=<?php echo $_GET['action']; ?>&type=test&test_date=<? echo $_GET['test_date']?>" method="post">
                <table border="1">                   
                    <tbody>
                        <thead>
                                    <th>You Cannot modify the test date:</br>
                                    <input type="text" name="date" value="<?echo "$test_date"?>" readonly="readonly"</th>
                                    
                        </thead>
                        <tr>
                            <td><label>DKH:</label>             <input type="text" name="dkh" value="<?echo "$dkh"?>"</td>
                            <td><label>Calcium:</label>         <input type="text" name="cal" value="<?echo "$cal"?>" /></td>
                            <td><label>PH Value:</label>        <input type="text" name="ph" value="<?echo "$ph"?>" /></td>
                        </tr>
                        <tr>
                            <td><label>Temperature:</label>     <input type="text" name="temp" value="<?echo "$temp"?>" /> </td>
                            <td><label>Salinity/SG:</label>     <input type="text" name="salinity" value="<?echo "$salinity"?>" /></td>
                            <td><label>ORP:</label>             <input type="text" name="orp" value="<?echo "$orp"?>" /> </td>
                        </tr>
                        <tr>                         
                            <td><label>Nitrate:</label>          <input type="text" name="no3" value="<?echo "$nitrate"?>" /></td>
                            <td><label>PO4:</label>             <input type="text" name="po4" value="<?echo "$po4"?>" /></td>
                            <td><label>Ammonia:</label>         <input type="text" name="ammon" value="<?echo "$amon"?>" /></td>
                        </tr>                                      
                    </tbody>
                </table>           
                    <input type="submit" value="Update Water Test" />
                </form>   
 		</div>
		<div id="aside">                    
                    <h3>
                        Info:
                    </h3>
                    <p>You may also view you log water test history from the menu options on the left</p>
		</div>
		<div id="footer">
			Copyright © ReefersLog, 2012, wkoester All Rights Reserved
		</div>
	</div>
</html>